<template>
  <div class="about">
    <span v-if="token"> <button @click="removeToken">退出登录</button></span>
    <span v-else> <router-link to = "/login">请登录</router-link></span>
    <h1>尝试get请求</h1>
    url: <input type="text" v-model="url">
    <button @click="test">发送请求</button>
    {{result}}
  </div>
</template>
<script>
import {mapState, mapMutations} from 'vuex'
export default {
  data() {
    return {
      result: "",
      url: "/admin"
    };
  },
  created() {
    this.test();
  },
  methods: {
    test() {
      this.$axios.get(this.$data.url).then(res => {
        this.$data.result = res.data;
      }).catch(err => {
        alert(err);
      });
    },
    ...mapMutations(['removeToken'])
  },
  computed: {
    ...mapState(['token'])
  }
}
</script>